<?php
namespace App\Http\Controllers\Api\System;

use App\User\UserBaseModel;
use App\Http\Controllers\Controller;
#use App\Library\alipay\aop\AopClient\AopClient;
require_once base_path().'/app/Library/alipay/AopSdk.php';
require_once base_path().'/app/Library/alipay/aop/AopClient.php';
class AliPayController extends Controller
{
    //支付宝参数
    private  $PublicKey  = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp63TFqQzEvQg5b7nVjNVqBmRHs/NlG6TsA0+Ghhj/WsBNhGm/Oa5588W6r7uU+1g+3wDmFKzYevd3RNFQu0PzipFMiV0bHgkQnNePnlZ1jyybTfX2PU5qcgCojmmt4eV24k937rPeJo7sHILPRiJOzyJeqcqI3Tgbtpp5ipY5RuqFiCD5hKB2vwGI7nzQmN6rRP9dZuRaKfgg0ysWc1HgLIdnZ1Fy7ZqhYHAvdm6qEV3QoO4wawfVEjtn4vlJ1hsl7C5DQw5ukFKqMcK2BpsYa9RXAYCpaQWKPdGeurQfnNgFKUdaIDEDkOkReiaq1/txm+A9M8qIBCqnbgs0WYaqwIDAQAB';
    private  $privateKey = 'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCnrdMWpDMS9CDlvudWM1WoGZEez82UbpOwDT4aGGP9awE2Eab85rnnzxbqvu5T7WD7fAOYUrNh693dE0VC7Q/OKkUyJXRseCRCc14+eVnWPLJtN9fY9TmpyAKiOaa3h5XbiT3fus94mjuwcgs9GIk7PIl6pyojdOBu2mnmKljlG6oWIIPmEoHa/AYjufNCY3qtE/11m5Fop+CDTKxZzUeAsh2dnUXLtmqFgcC92bqoRXdCg7jBrB9USO2fi+UnWGyXsLkNDDm6QUqoxwrYGmxhr1FcBgKlpBYo90Z66tB+c2AUpR1ogMQOQ6RF6JqrX+3Gb4D0zyogEKqduCzRZhqrAgMBAAECggEAS3/8LRSwHpen/Gqx9WFV70Pb0RjWQ0Bq5XmA/fT/iMrWl8bo/rTQ/myDsB1aaJXY9kOHxt1uAeh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F5Iz76HWCC1arZmM6QNGqxKnLKSChHkfJGCosKnC3taTWQleJa4pcFi1rxlwck60/vmKe++dFw==';
    private  $aliPubKey  = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs7TVB7g0fdkpgGgc1wp8WYAN9CIQ/UxvfcVpG9Qu0MmK4XTgp8y2NHvez4TNUgPoEchQxd1ChDJfrhB/jtOSwsh5gxjhEb6heN8c5Fp4BvxoiVDBN9XR7a54jbCe236EbF1e3DvZqc8wqSFyOLhxwghGRaFRzmpfi39Up16CnowYOeh6MwbVAvibifOr94cif8PwpD/mKrKOcIWTAFmhyigvVuXHvgSEo1H84KuV/CkaaZM7mJQF4Y6/VTp4yIgOuHIGpM+XWYTOB8rqvMUNljmaRtU/b2xX/3uhW2gpeRuG2TzS1m3x6O1ddkYwRoD4iJ09nbcExnOe+sPZNOoS4wIDAQAB';
    private  $APPID      = '2018011801951667';


    public final function pay($order_sn='123456789',$amount='1',$subject='123',$type=0)
    {
        $content                    = array();
        $content['subject']         = $subject;
        $content['out_trade_no']    = $order_sn;
        $content['body']            = '神鲸科技';
        $content['total_amount']    = $amount;
        $content['product_code']    = "QUICK_MSECURITY_PAY";
        $content['passback_params'] = $type;
        $con                        = json_encode($content);//$content是biz_content的值,将之转化成json字符串
        try
        {
            $aop = new \AopClient ();
            $aop->gatewayUrl            = 'https://openapi.alipay.com/gateway.do';
            $aop->appId = $this->APPID;
            $aop->rsaPrivateKey         = $this->privateKey;
            $aop->alipayrsaPublicKey    = $this->aliPubKey;
            $aop->apiVersion            = '1.0';
            $aop->postCharset           ='utf-8';
            $aop->format                ='json';
            $aop->signType              = 'RSA2';
            //生成随机订单号
            $request                    = new \AlipayTradeAppPayRequest();
            //异步地址传值方式
            $NotifyUrl                  = 'http://zhaijidi.zhongmawan.com/notify';
            $request->setNotifyUrl($NotifyUrl);
            $request->setBizContent($con);
            $result                     = $aop->sdkExecute($request);
            if (empty($result)) {
                return self:: response(null,'3','创建支付信息失败');
            } else {
                return self::response(['param'=>$result],'200');
            }
        } catch(Exception $e) {
            return self::response(null,'4','创建支付信息失败');
        }
    }


    public function checkRAS(){

        $aop = new \AopClient ();
        $aop->alipayrsaPublicKey = $this->PublicKey;
        //此处验签方式必须与下单时的签名方式一致
        $flag = $aop->rsaCheckV1($_POST, NULL, "RSA");
        return $flag;
        //验签通过后再实现业务逻辑，比如修改订单表中的支付状态。
    }



}
